package sys
{
	import flash.display.Sprite;
	
	import WInterface.IEvent;
	import WInterface.ISys;
	

	/**
	 *事件处理类
	 * @author 张进辉
	 * 
	 */	
	public class CoreEvent implements ISys
	{
		private var _debug:Boolean;
		/**事件对象组*/
		private var _eventObjects:Vector.<IEvent> = new Vector.<IEvent>();
		
		/**
		 *构造函数 
		 * 
		 */		
		public function CoreEvent(app:Sprite)
		{
			if(!Fcade.open)
				throw new Error("不要尝试实例化该类");
		}
		
		/**
		 *指定对象是否激活事件功能 
		 * @param item
		 * @return 
		 * 
		 */		
		public final function hasEventItem(item:IEvent):Boolean
		{
			for each (var i:IEvent in _eventObjects) 
			{
				if(i == item)
					return true;
			}
			return false;
			
		}
		
		/**
		 *增加一个事件类 
		 * @param item
		 * 
		 */		
		public final function addEventItem(item:IEvent):void
		{
			if(hasEventItem(item)) return;
			
			_eventObjects.push(item);
		}
		
		/**
		 *删除一个事件类 
		 * @param item
		 * 
		 */		
		public final function delEventItem(item:IEvent):void
		{
			for (var i:int = 0; i < _eventObjects.length; i++) 
			{
				var eventObj:IEvent = _eventObjects[i];
				if(eventObj == item)
				{
					_eventObjects.splice(i,1);
					return;
				}
			}
		}
		
		/**
		 *进行事件回调 
		 * @param type
		 * @param data
		 * 
		 */		
		public final function tickEvent(type:String,data:Object):void
		{
			for each (var i:IEvent in _eventObjects) 
			{
				if(i.hasEvent(type))
					i.eventCallback(type,data);
			}
		}
		
		
		
		public function set debug(value:Boolean):void
		{
			_debug = value;
		}
		
		public function get debug():Boolean
		{
			return _debug;
		}
		
	}
}